package com.feeyo.groundservice.easyphoto.utils.color

/**
 * Created by huan on 2018/1/9.
 */
object ColorUtils {
    /**
     * 判断颜色是否偏黑色
     *
     * @param color 颜色
     * @return
     */
    @JvmStatic
    fun isBlackColor(color: Int): Boolean {
        val grey = toGrey(color)
        return grey < 50
    }

    /**
     * 颜色转换成灰度值
     *
     * @param rgb 颜色
     * @return　灰度值
     */
    @JvmStatic
    fun toGrey(rgb: Int): Int {
        val blue = rgb and 0x000000FF
        val green = (rgb and 0x0000FF00) shr 8
        val red = (rgb and 0x00FF0000) shr 16
        return (red * 38 + green * 75 + blue * 15) shr 7
    }

    @JvmStatic
    fun isWhiteColor(color: Int): Boolean {
        val grey = toGrey(color)
        return grey > 200
    }
}
